package com.kinghood.productcenter.common.model.dto.sku;

import com.kinghood.productcenter.common.model.dto.product.ProductSkuExtrasReqDTO;
import com.kinghood.productcenter.common.model.dto.product.ProductSupplierReqDTO;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2024-01-22 15:04
 **/
@Data
public class UpdateProductSkuReqDTO implements Serializable {

    /**
     * 商品id
     * */
    @NotNull
    private Long productId;
    /**
     * 只有在修改的时候使用
     * */
    private ProductSkuReqDTO sku;
    /**
     * sku
     */
    @NotEmpty
    private List<ProductSkuReqDTO> skuList;
    /**
     * sku计价
     * 入参的时候封装回sku
     */
    private List<ProductSkuReqDTO> skuPriceList;
    /**
     * sku附件
     */
    private List<ProductSkuExtrasReqDTO> skuExtrasList;
    /**
     * sku
     */
    private List<ProductSupplierReqDTO> skuSupplierList;

    /**
     * 获取属性的code
     * */
    public List<String> getAttributeCode(){
        ArrayList<String> res = new ArrayList<>();
        if(!CollectionUtils.isEmpty(skuList)){
            skuList.forEach(x->{
                if (!CollectionUtils.isEmpty(x.getAttributes())) {
                    res.addAll(x.getAttributes().keySet());
                }
            });
        }
        if(!CollectionUtils.isEmpty(skuPriceList)){
            skuPriceList.forEach(x->{
                if (!CollectionUtils.isEmpty(x.getAttributes())) {
                    res.addAll(x.getAttributes().keySet());
                }
            });
        }
        if(!CollectionUtils.isEmpty(skuExtrasList)){
            skuExtrasList.forEach(x->{
                if (!CollectionUtils.isEmpty(x.getAttributes())) {
                    res.addAll(x.getAttributes().keySet());
                }
            });
        }
        if(!CollectionUtils.isEmpty(skuSupplierList)){
            skuSupplierList.forEach(x->{
                if (!CollectionUtils.isEmpty(x.getAttributes())) {
                    res.addAll(x.getAttributes().keySet());
                }
            });
        }
        return res;
    }
}
